<head>
@extends('layouts.admin_common')
@section('content')
<!-- SSLの場合 -->
@if(app('env')=='production')
<link rel="stylesheet" href="{{ secure_asset('/css/sale.css') }}">
<script src="{{ secure_asset('/js/home.js') }}"></script>
@else
<!-- SSLではない場合 -->
<link rel="stylesheet" href="{{ asset('/css/sale.css') }}">
<script src="{{ asset('/js/home.js') }}"></script>
@endif

</head>

<div class="breadcrumbs_container">
    {{Breadcrumbs::render('admin.news') }}
</div>
<div class="system_tab_line"></div>
<style type="text/css">
    #login{
        display:none;
        border:1px solid #3366FF;
        height:65%;
        width:50%;
        position:absolute;
        top:12%;
        left:24%;
        z-index:2;
        background: white;
    }
    #over{
        width: 100%;
        height: 100%;
        opacity:0.8;
        filter:alpha(opacity=80);
        display: none;
        position:absolute;
        top:0;
        left:0;
        z-index:1;
        background: silver;
    }
</style>

<script type="text/javascript">
    function show()
    {
        var login = document.getElementById('login');
        var over = document.getElementById('over');
        login.style.display = "block";
        over.style.display = "block";
    }
    function hide()
    {
       var login = document.getElementById('login');
        var over = document.getElementById('over');
        login.style.display = "none";
        over.style.display = "none";
    }
</script>
<script type="text/javascript">
function onSubmit(op){
	var setRate = document.getElementById("title");
	var setFeed = document.getElementById("detail");
	var setUnpaid = document.getElementById("sort_num");

	if(trim(title.value)==null || trim(title.value)==""){
		alert("タイトルを入力してください！");
		title.focus();
		return false;
	}
	if(trim(detail.value)==null || trim(detail.value)==""){
		alert("詳細を入力してください！");
		detail.focus();
		return false;
	}
	if(trim(sort_num.value)==null || trim(sort_num.value)==""){
		alert("カウントを入力してください！");
		sort_num.focus();
		return false;
	}
	var form = document.getElementById('newsForm');
	form.action="news/"+op;
	form.submit();
}
function trim(str){

	   return str.replace(/(^\s*)|(\s*$)/g, "");

}
function onSubmitDel(op,newsId){
	document.getElementById('news_id').value=newsId;
  	if (false === confirm('削除しますか？') )return;
	var form = document.getElementById('newsForm');

	form.action="news/"+op;

	form.submit();
}
function onSubmitUpdate(op,newsId){

	  if (document.getElementById("divNewsUpdate"+newsId).style.display == "none"){
		  document.getElementById("divNewsUpdate"+newsId).style.display = "block";
		  document.getElementById("divNm"+newsId).style.display = "none";
		  document.getElementById("divNewsUpdate0"+newsId).style.display = "block";
		  document.getElementById("divNm0"+newsId).style.display = "none";
		  document.getElementById("divNewsUpdate1"+newsId).style.display = "block";
		  document.getElementById("divNm1"+newsId).style.display = "none";
		  document.getElementById("btnID"+newsId).value = "保存";
	   }else {
		  document.getElementById("divNewsUpdate"+newsId).style.display = "none";
		  document.getElementById("divNm"+newsId).style.display = "block";
		  document.getElementById("divNewsUpdate0"+newsId).style.display = "none";
		  document.getElementById("divNm0"+newsId).style.display = "block";
		  document.getElementById("divNewsUpdate1"+newsId).style.display = "none";
		  document.getElementById("divNm1"+newsId).style.display = "block";
		  document.getElementById("btnID"+newsId).value = "修正 ";

	      document.getElementById('news_id').value=newsId;
		  var form = document.getElementById('newsForm');

		  form.action="news/"+op;
		  form.submit();
	   }
}
function cancelSale(){

	window.location.href=('home');

}
</script>
<div id="outDiv">
<form class="form-inline" id="newsForm" method="post">
			<table class="table table-condensed">
				<tr>
					<td>タイトル</td>
					<td>詳細</td>
					<td>カウント</td>
					<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
				</tr>

				@foreach ($allNewsInfo as $newsInfo)
				<tr>
    				    <td>
        				    <div id="divNewsUpdate{{$newsInfo->news_id}}" style="display:none; border: 1px solid #1E90FF;width:328px;-webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(102, 175, 233, .6);box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(102, 175, 233, .6);">
                                <input type="text" id='titleNews' name="titleNews{{$newsInfo->news_id}}" size="30" class="form-control" value="{{$newsInfo->title}}">
                            </div>
        				    <div id="divNm{{$newsInfo->news_id}}">{{$newsInfo->title}} </div>
    				    </td>
						<td>
    				      <div style="width:394px; white-space:nowrap;overflow:hidden;text-overflow:ellipsis;"  title="{{$newsInfo->detail}}">
    				          <div id="divNewsUpdate0{{$newsInfo->news_id}}" style="display:none; border: 1px solid #1E90FF;">
                               <textarea id='detailNews' name="detailNews{{$newsInfo->news_id}}" cols="40" rows="5" class="form-control">{{$newsInfo->detail}}</textarea>
                              </div>
        				      <div id="divNm0{{$newsInfo->news_id}}">{{$newsInfo->detail}}</div>

    				      </div>
    				    </td>
                         <td>
                         <div id="divNewsUpdate1{{$newsInfo->news_id}}" style="display:none; border: 1px solid #1E90FF; width:118px;-webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(102, 175, 233, .6);box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(102, 175, 233, .6);">
                               <input type="text" id='sort_numNews' name="sort_numNews{{$newsInfo->news_id}}" size="6" class="form-control" value="{{$newsInfo->sort_num}}">
                              </div>
        				      <div id="divNm1{{$newsInfo->news_id}}">{{$newsInfo->sort_num}}</div>
                         </td>
					<td><input type="button" value="修正"
						class="btn btn-primary button_normal"
						onclick="onSubmitUpdate('update','{{$newsInfo->news_id}}')" id="btnID{{$newsInfo->news_id}}"/>
						<input type="button" value="削除" class="btn btn-primary button_normal"
						onclick="onSubmitDel('delete','{{$newsInfo->news_id}}')" />
						</td>
				</tr>
				@endforeach
			</table>
			<table border="0" cellspacing="0" style="width: 1300px;">
				<tr>
					<td align="right" style="width: 725px;"><input type="button" value="新規"
						class="pure-button pure-button-primary button_normal"
						onclick="show()" /></td>
					<td align="right" style="width: 50px;"><input type="button" value="@lang('messages.cancel')"
						class="pure-button pure-button-primary button_normal"
						onclick="cancelSale()" /></td>
                </tr>
			</table>
			<div>@if(isset($success)) {{$success}} @endif</div>
		    <div>@if(isset($error)) {{$error}} @endif</div>
		    <input type="hidden" name="news_id" id="news_id">
			<input type="hidden" name="_token" value="{{csrf_token()}}">
<!-- show div start-->

            <div id="login">
              <div>
                <table id="tblData" class="table table-condensed">
                <div class="breadcrumbs_container">
                {{Breadcrumbs::render('admin.news')}}
        	    </div>
                <div class="system_tab_line"></div>
                     <tr>
					    <td>タイトル</td>
                        <td><input type="text" id='title' name="title" size="30" class="form-control"></td>
                        <td></td>
				    </tr>
				     <tr>
					    <td>詳細</td>
                        <td><textarea id='detail' name="detail" cols="50" rows="5" class="form-control"></textarea></td>
                        <td></td>
				    </tr>
					<tr>
					    <td>カウント</td>
                        <td><input type="text" id='sort_num' name="sort_num" size="6" class="form-control"></td>
                        <td></td>
				    </tr>
				    </table>

				   <div style=" margin-right:90px;margin-top:70px; float:right;">
				      <button type="button" class="button_add_sale pure-button pure-button-primary" value="@lang('messages.save')" onclick="onSubmit('create');">@lang('messages.save')</button>&nbsp;&nbsp;
				      <button type="button" class="button_add_sale pure-button pure-button-primary" value="閉じる" onclick="hide();" style="background-color: #909497;">閉じる</button>
				   </div>
                </div>
            </div>
            <div id="over"></div>
<!-- show div end-->
</form>

</div>
@endsection
